/*
 * Copyright (c) 2015. For Intelligent Group.
 */

package com.intelligent.ispc.client.event;

import com.google.common.eventbus.Subscribe;
import com.intelligent.ispc.client.core.view.analysis.report.YieldPanel;
import com.intelligent.ispc.client.core.view.analysis.spc.SpcMainPanel;
import com.intelligent.ispc.client.utils.ApplicationBeanUtils;
import com.intelligent.ispc.client.utils.UIConstant;

/**
 * Created by cherry on 2016/8/18.
 */
public class SearchParamsChangeListener {

    /**
     * Subscribe event for changing spc search parameters.
     *
     * @param event SearchParamsChangeEvent
     */
    @Subscribe
    public void spcChange(SearchParamsChangeEvent event) {
        try {
            if (event.getModule().equals(UIConstant.MODULE_SPC)) {
                if (event.getType().equals(SearchParamsChangeEvent.TYPE_FILE)) {
                    ApplicationBeanUtils.getBean(SpcMainPanel.class).onChooseFileChange(event.isMatched());
                } else if (event.getType().equals(SearchParamsChangeEvent.TYPE_ITEM)) {
                    ApplicationBeanUtils.getBean(SpcMainPanel.class).onChooseItemChange(event.isMatched());
                } else if (event.getType().equals(SearchParamsChangeEvent.TYPE_CONDITION)) {
                    ApplicationBeanUtils.getBean(SpcMainPanel.class).onSearchConditionChange(event.isMatched());
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Subscribe event for changing yield search parameters.
     *
     * @param event SearchParamsChangeEvent
     */
    @Subscribe
    public void yieldChange(SearchParamsChangeEvent event) {
        try {
            if (event.getModule().equals(UIConstant.MODULE_YIELD)) {
                if (event.getType().equals(SearchParamsChangeEvent.TYPE_FILE)) {
                    ApplicationBeanUtils.getBean(YieldPanel.class).onChooseFileChange(event.isMatched());
                } else if (event.getType().equals(SearchParamsChangeEvent.TYPE_ITEM)) {
                    ApplicationBeanUtils.getBean(YieldPanel.class).onChooseItemChange(event.isMatched());
                } else if (event.getType().equals(SearchParamsChangeEvent.TYPE_CONDITION)) {
                    ApplicationBeanUtils.getBean(YieldPanel.class).onSearchConditionChange(event.isMatched());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
